﻿using System.Collections.Generic;
using System.Threading;
using SilverlightApplication1.Controls;
using SilverlightApplication1.Interfaces;

namespace SilverlightApplication1.Models
{
    public class BoxModel
    {
        private readonly List<IAnimated> scenario = new List<IAnimated>();

        public void AddToScenario(IAnimated control)
        {
            scenario.Add(control);
        }
        public void RunAnimation()
        {
            if (scenario.Count > 1)
            {
                for (int i = 0; i < scenario.Count - 1; i++)
                {
                    scenario[i].AnimationCompleted += scenario[i + 1].RunAnimation;
                }
                scenario[0].RunAnimation();
            }
        }

        public void StopAnimation()
        {
            foreach (var animatedControl in scenario)
            {
                animatedControl.StopAnimation();
            }
        }
    }
}